package sample.user.dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.Update;

import sample.user.entity.UserEntity;

@Mapper
public interface UserMapperAnnotation {

	public static String SelectSQL = "SELECT ID, Name, Sex,Age,Describe FROM T_USER";
	public static String SelectKey = "SELECT (SELECT max(Id) FROM T_USER)+1";
	public static String InsertSQL = "INSERT INTO T_USER(ID,Name,Sex,Age,Describe) VALUES(#{id},#{name}, #{sex}, #{age}, #{describe})";
	
	@Select(SelectSQL)
	public List<UserEntity> getUser();

	@Insert(InsertSQL)
	@SelectKey(statement = SelectKey, keyProperty = "id", keyColumn ="ID", before = true, resultType = int.class)
	public void addUser(UserEntity userEntity);

	@Delete("DELETE FROM T_USER WHERE id = #{id}")
	public void deleteUser(int id);
	
	@Update("UPDATE T_USER SET Describe=#{describe} WHERE id =#{id}")
	public void updateUser(UserEntity userEntity);

}
